Assignemnt: #117 and More Number Puzzles
Code
/// Name: Yordan Rashkov
/// Period: 7
/// Program Name: More Number Puzzles
/// File Name: morenumpuzz.java
/// Date Finished: 5/5/2016
import java.util.Scanner;
import java.util.InputMismatchException;
public class morenumpuzz
{
public static void main( String[] args ) throws Exception
{
System.out.println();
int c = 0;
do
{
c = showMenu();
System.out.println("\n");
if (c==1) optionOne();
if (c==2) optionTwo();
System.out.println("\n");
}
while (c!=3);
System.out.println("Bye then.");
}
public static int showMenu()
{
System.out.print("1) Find two digit numbers <= 56 with sums of digits > 10\n" +
"2) Find two digit number minus number reversed which equals sum of digits\n" +
"3) Quit\n" +
"\n" +
">");
Scanner keyboard = new Scanner(System.in);
int n = 0;
try
{
n = keyboard.nextInt();
}
catch (InputMismatchException e)
{
System.out.println("WRONG INPUT");
}
if (n < 1 || n > 3) System.out.println("Enter a number between 1 and 3 !!!!");
return n;
}
public static void optionOne()
{
for ( int i = 1; i < 10; i++)
{
for ( int j = 0; j < 10; j++)
{
if ((i*10+j)<=56 && (i+j>10) )
{
System.out.print(i);
System.out.print(j + " ");
}
}
}
}
public static void optionTwo()
{
for ( int i = 1; i < 10; i++)
{
for ( int j = 0; j < 10; j++)
{
if ((i*10+j)-(j*10+i)==(i+j) )
{
System.out.print(i);
System.out.print(j+" ");
}
}
}
}
}